<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'
export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        supplierNo: {
          label: '供货商编号',
          placeholder: '请输入供货商编号'
        },
        supplierName: {
          label: '供货商名称',
          placeholder: '请输入供货商名称'
        },
        mobilePhoneNumber: {
          label: '手机号',
          placeholder: '请输入手机号'
        },
        parentId: {
          label: '所属父类',
          placeholder: '请输入父类',
          type: 'list',
          list: []

        },
        remark: {
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入备注'
        },

        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.initSupplierParentList()
      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('supplierName', 'status'),
        initApi: 'supplierApi/supplierInfoInfo',
        saveApi: 'supplierApi/saveSupplierInfo',
        updateApi: 'supplierApi/updateSupplierInfo',
        objectName: 'supplierInfo'
      })
    },
    initSupplierParentList() {
      mRequest('supplierApi/getSupplierParentList', {}, (res) => {
        this.dataFormConfig['parentId'].list = this.R.pathOr([], ['data', 'list'], res)
      })
    },
  }
}
</script>
